package com.gx.smart.building.ui.assets.fragment

import android.view.ViewGroup
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.TimeUtils
import com.gx.smart.base.BaseMVVMFragmentV2
import com.gx.smart.building.R
import com.gx.smart.building.databinding.FragmentAssetsDetailBinding
import com.gx.smart.building.ui.assets.viewmodel.AssetsViewModel
import com.gx.smart.common.util.AppConfig

class AssetsDetailFragment : BaseMVVMFragmentV2<AssetsViewModel>() {

    private lateinit var viewBinding: FragmentAssetsDetailBinding

    companion object {
        @JvmStatic
        fun newInstance() = AssetsDetailFragment()
    }

    override fun onBindLayout(): Int = R.layout.fragment_assets_detail

    override fun getToolbarTitle(): String = ""

    override fun enableToolbar(): Boolean = false

    override fun onBindViewModel(): Class<AssetsViewModel> = AssetsViewModel::class.java

    override fun enableStatusBar(): Boolean = false
    override fun initContentView(root: ViewGroup) {
        viewBinding = FragmentAssetsDetailBinding.inflate(layoutInflater, root, true)
    }

    override fun initData() {
        //资产详情查询
        val id = requireActivity().intent.getStringExtra("id")
        val userId = SPUtils.getInstance().getString(AppConfig.USER_ID)
        viewModel.queryAssetDetail(id!!, userId).observe(viewLifecycleOwner) {
            viewBinding.assetCode.text = it.assetCode
            viewBinding.assetName.text = it.assetName
            viewBinding.assetTypeName.text = it.assetTypeName
            viewBinding.brandName.text = it.brandName
            viewBinding.modelName.text = it.modelName
            viewBinding.serialNo.text = it.serialNo
            viewBinding.price.text = it.price.toString()
            if (it.purchaseDate.isNotBlank()) {
                viewBinding.purchaseDate.text =
                    TimeUtils.millis2String(it.purchaseDate.toLong(), "yyyy-MM-dd")
            }
            viewBinding.fixedNumberOfYear.text = it.fixedNumberOfYear
            //1 库存 2 正常 3 维修 4 异常 5 报废
            viewBinding.status.text = when (it.status) {
                1 -> "库存"
                2 -> "正常"
                3 -> "维修"
                4 -> "异常"
                5 -> "报废"
                else -> ""
            }
            viewBinding.areaName.text = it.areaName
            viewBinding.assetSourceName.text = it.assetSourceName
            viewBinding.supplierName.text = it.supplierName
            viewBinding.concatPhone.text = it.concatPhone
        }
    }
}